package com.swak.frame.dto.response;

import java.util.List;

import com.swak.frame.dto.base.RestApiCode;
import com.swak.frame.dto.base.SysRestCode;

public final class Responses {

	/** 成功返回的对象 **/
	public static Response SUCC = new Response(SysRestCode.SUCC);

	/** 失败返回的对象 **/
	public static Response FAIL = new Response(SysRestCode.SYS_ERR);

	public static int buildResponse;

	public static <T> RpcResponse.Builder<T> builder() {
		return new RpcResponse.Builder<T>();
	}

	public static <T> RpcResponse.Builder<T> builder(String errCode, String errMessage) {
		return new RpcResponse.Builder<T>().of(errCode, errMessage);
	}

	public static <T> RpcResponse.Builder<T> builder(RestApiCode restCode) {
		return builder(restCode.getRetCode(), restCode.getRetMessage());
	}

	public static <T> MultiResponse.Builder<T> multiBuilder() {
		return new MultiResponse.Builder<T>();
	}

	public static <T> MultiResponse.Builder<T> multiBuilder(String errCode, String errMessage) {
		return new MultiResponse.Builder<T>().of(errCode, errMessage);
	}

	public static <T> MultiResponse.Builder<T> multiBuilder(RestApiCode restCode) {
		return multiBuilder(restCode.getRetCode(), restCode.getRetMessage());
	}

	
	/*************************************buildResponse**********************************************/
	
	public static <T> RpcResponse<T> buildResponse(String errCode, String errMessage) {
		return new RpcResponse<T>(errCode, errMessage);
	}

	public static <T> RpcResponse<T> buildResponse(RestApiCode restCode) {
		return buildResponse(restCode.getRetCode(), restCode.getRetMessage());
	}

	public static <T> RpcResponse<T> buildResponse(T data) {
		return new RpcResponse<T>(data);
	}

	public static <T> RpcResponse<T> buildResponse() {
		return buildResponse(SysRestCode.SUCC);
	}

	public static <T> MultiResponse<T> buildResponse(List<T> data, int total) {
		MultiResponse<T> multiResponse = new MultiResponse<T>();
		multiResponse.setResult(data);
		multiResponse.setTotal(total);
		return multiResponse;
	}
}
